version: "2"

services:
  elasticsearch:
    image: "{{ nexus_docker_proxy | default('docker.elastic.co') }}elasticsearch/elasticsearch:{{ elk.version }}"
    container_name: "{{ es_node_name }}"
    network_mode: "host"
    volumes:
      - "{{ elk.deploy_path }}/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro"
      - "{{ elk.deploy_path }}/config/certs:/usr/share/elasticsearch/config/certs:ro"
      - "{{ elasticsearch.path_logs }}:{{ elasticsearch.path_logs }}"
{% for path in elasticsearch.path_data %}
      - "{{ path }}:{{ path }}"
{% endfor %}
    environment:
      TZ: "Asia/Shanghai"
      CONFIG_HASH: "{{ lookup('template', role_path + '/templates/elasticsearch.yml.j2') | striptags | trim | hash('md5') }}" # Trigger restart when config file changed
      ES_SETTING_BOOTSTRAP_MEMORY__LOCK: "true"
      ES_JAVA_OPTS: "-Xms{{ elasticsearch.mem_limit }} -Xmx{{ elasticsearch.mem_limit }}"
      ES_PATH_DATA: "[{% for path in elasticsearch.path_data %}'{{ path }}:{{ path }}'{{ (loop.last) | ternary('', ',') }}{% endfor %}]"
      ES_NETWORK_HOST: "{{ global_bond_ip }}"
{% if enrollment_token is defined %}
      ENROLLMENT_TOKEN: "{{ enrollment_token }}"
{% endif %}
{% if bootstrap is defined %}
      ELASTIC_PASSWORD: "${ELASTIC_PASSWORD}"
{% endif %}
    ulimits:
      memlock:
        soft: -1
        hard: -1
    healthcheck:
      test:
        [
          "CMD-SHELL",
          "curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'",
        ]
      interval: 10s
      timeout: 10s
      retries: 120